package com.zrx.govern.component.easyexcel.starter.strategy;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.style.column.AbstractHeadColumnWidthStyleStrategy;
import com.zrx.govern.component.easyexcel.starter.entity.ExcelField;

import java.util.List;

/**
 * @author zhangxiaowei
 * @desc 自定义列宽策略
 */
public class ExcelAutoColumnWidthStyleStrategy extends AbstractHeadColumnWidthStyleStrategy {

    private List<ExcelField> fieldList;

    public ExcelAutoColumnWidthStyleStrategy(List<ExcelField> fieldList) {
        this.fieldList = fieldList;
    }

    /**
     * withTemplate模式下，head为null
     * @param head
     * @param columnIndex
     * @return
     */
    @Override
    protected Integer columnWidth(Head head, Integer columnIndex) {
        return fieldList.get(columnIndex.intValue()).getWidth();
    }
}
